package com.oxy.util;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;

public class SysErrManager {
	private Log logger = null;
	
	/*
	 * Define system errors here
	 */
	public static final class ERRORS {
		public static final int UNKNOWN_ERR = 1000;
		public static final int INTERNAL_ERR = 1001;
		
		public static final int DATA_ACCESS_ERR = 2001;
		
		public static final Map<Integer, String> errCdDescMap = new HashMap<Integer, String>();
		static {
			errCdDescMap.put(new Integer(UNKNOWN_ERR), "Unknown Error");
			errCdDescMap.put(new Integer(INTERNAL_ERR), "System Internal Error");
			
			errCdDescMap.put(new Integer(DATA_ACCESS_ERR), "Data Access Error");
		}
		
		public static final String getErrDesc(int errCd) {
			String desc = errCdDescMap.get(new Integer(errCd));
			if(desc == null) {
				desc = "Error description not found";
			}
			return desc;
		}
	}
	
	// 需要一个logmanager来获取log打印syserr详情
	public SysErrManager(LogManager logMgr) {
		logger = logMgr.getLogCommon();
	}
	
	public SysErrException makeSysError(int errCd, String errMsg, Throwable cause) {
		SysErrException ret = new SysErrException(errCd, errMsg, cause);
		logger.error("Got System Error, details:\r\n"+ret.toString());
		return ret;
	}
	
	public SysErrException makeSysError(int errCd, String errMsg) {
		SysErrException ret = new SysErrException(errCd, errMsg);
		logger.error("Got System Error, details:\r\n"+ret.toString());
		return ret;
	}
	
	public SysErrException makeSysError(int errCd, Throwable cause) {
		SysErrException ret = new SysErrException(errCd, cause);
		logger.error("Got System Error, details:\r\n"+ret.toString());
		return ret;
	}
	public SysErrException makeSysError(int errCd) {
		SysErrException ret = new SysErrException(errCd);
		logger.error("Got System Error, details:\r\n"+ret.toString());
		return ret;
	}
}
